// import { awaitWrap, confirmAction } from '@/assets/js/tool'
import { awaitWrap, confirmAction } from '@src/assets/js/tool'
import { message, Space } from 'antd'
import React from 'react'
import { delRequest } from './ajax'

async function delHandle (id, callback) {
  const h = message.loading('删除中')
  const [e] = await awaitWrap(delRequest(id))
  h()
  if (e === null) {
    message.success('删除成功')
    callback()
  }
}

export function getColumns (common, setVisible, setModifyData, refreshFn) {
  return [
    {
      title: '序号',
      dataIndex: 'index',
      key: 'index',
      align: 'center',
      width: '60px'
    },
    {
      title: '鉴定机构名称',
      dataIndex: 'name',
      key: 'name',
      width: 100
    },
    {
      title: '鉴定机构类型',
      dataIndex: 'type',
      key: 'type',
      width: 100
    },
    {
      title: '联系人',
      dataIndex: 'contact',
      key: 'contact',
      width: 100
    },
    {
      title: '联系电话',
      dataIndex: 'tel',
      key: 'tel',
      width: 100
    },
    {
      title: '状态',
      dataIndex: 'status',
      key: 'status',
      width: 100,
      render: (v) => {
        return v === 1 ? '正常' : '停止指定'
      }
    },
    {
      title: '操作',
      dataIndex: 'index',
      key: 'operate',
      width: 60,
      render: (value, line) => {
        return (
          <Space size='middle'>
            <a onClick={() => { setModifyData(line); setVisible(true) }}>修改</a>
            <a onClick={() => { confirmAction(`您确定要删除 ${line.name} 吗？`, () => { delHandle(line.id, refreshFn) }) }}>删除</a>
          </Space>
        )
      }
    }
  ]
}
